package com.ht.medicaltreatment.fragment

import android.content.Intent
import android.view.View
import androidx.fragment.app.viewModels
import androidx.recyclerview.widget.LinearLayoutManager
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.listener.OnItemClickListener
import com.gym.baselib.base.BaseFragment
import com.ht.medicaltreatment.R
import com.ht.medicaltreatment.activity.StockActivity
import com.ht.medicaltreatment.adapter.OrderFragmentAdapter
import com.ht.medicaltreatment.bean.OrderAllBean
import com.ht.medicaltreatment.viewmodel.OrderStockViewModel
import kotlinx.android.synthetic.main.fragment_all_layout.*

class AllFragment :BaseFragment(), /*OnRefreshListener,*/ OnItemClickListener {

    private val model by viewModels<OrderStockViewModel>()
    private val adapter = OrderFragmentAdapter()
    override fun getLayoutResId() = R.layout.fragment_all_layout

    override fun init() {
        //refreshLayout.setEnableRefresh(true)
        //refreshLayout.setOnRefreshListener(this)

        recyclerView.layoutManager = LinearLayoutManager(requireContext())
        recyclerView.adapter = adapter
        adapter.setOnItemClickListener(this)
        showProgress()
        model.requestAllData {
            dismissProgress()
            adapter.setNewInstance(it)
        }
    }

    /*override fun onRefresh(refreshLayout: RefreshLayout) {
        model.requestAllData {
            adapter.setNewInstance(it)
            refreshLayout.finishRefresh()
        }
    }*/

    override fun onItemClick(adapter: BaseQuickAdapter<*, *>, view: View, position: Int) {
        val item = adapter.data.get(position) as OrderAllBean
        startActivity(StockActivity.getIntent(requireContext(),item.id,StockActivity.FROM_ORDER))
    }

}
